#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2018/8/21 17:19
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 中级-递增的三元子序列.py
# @Software: PyCharm


class Solution:
    def increasingTriplet(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        ap = False
        a = -1
        bp = False
        b = -1
        for i in range(len(nums)):
            # ans
            if bp and nums[i] > b:
                return True
            # change b
            if not bp:
                if ap and nums[i] > a:
                    b = nums[i]
                    bp = True
            elif ap:
                if a < nums[i] < b:
                    b = nums[i]
                    bp = True
            # change a
            if ap:
                if nums[i] <a:
                    a = nums[i]
            else:
                a = nums[i]
                ap = True
        return False


def main():
    solve = Solution()
    nums = [5, 4, 3, 2, 1]
    print(nums)
    print(solve.increasingTriplet(nums))


if __name__ == '__main__':
    main()